from nicegui import ui,app

from ServerSide.Model.Stocks import StocksDal, StocksModel
from ServerSide.UserUi.UIModel import AStock


@ui.page('/show/{code}')
def showRecommend(code:str):
    alsll = StocksDal()
    print(code)
    # today=time.strftime("%Y-%m-%d", time.localtime())
    # today ="2023-05-05"
    rows = alsll.findByDate(code)
    ui.label(code+" 推荐")
    with ui.column():
        for row in rows:
            # print(row.id, row.name, row.code)
            ui.label(row.name)
    with ui.header():
        ui.button('首页', on_click=lambda: ui.open("/"))
#nicegui auto jump to another page




from typing import List

@app.post("/getListOfAStock")
async def getListOfAStock(ListOfAStock:List[AStock]):
    for i in ListOfAStock:
        print(i.name)
        print(i.code)
        asto = StocksModel(name=i.name, code=i.code)
        try:
            asto.save()
        except Exception as e:
            StocksModel.create_table()
            asto.save()